//
//  PathManager.m
//  HangzhouDaily
//
//  Created by zjun86 on 10-8-16.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//
//modified by yangmin at DT. on 2012-8-1.
//qq :415792212
//email:yangmin@me.com

#import "PathManager.h"
#import "ConstantHeader.h"

@implementation PathManager

#pragma mark - singleton
static PathManager * shared = nil;

+(PathManager *)sharedPathManager{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shared=[[PathManager alloc]init];
    });
    
    return shared;
}
+ (id)allocWithZone:(NSZone *)zone {
    __block id singleTon=nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shared=[super allocWithZone:zone];
        singleTon=shared;
    });
    return singleTon;
}
- (id)copyWithZone:(NSZone *)zone {
    return self;
}

- (id)init {
    if (self = [super init]){
     

    }
    return self;
}


#pragma mark - pathMethod
+ (BOOL) buildPath:(NSString *)path
{
    if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
        return [[NSFileManager defaultManager] createDirectoryAtPath:path
                                         withIntermediateDirectories:YES
                                                          attributes:nil
                                                               error:NULL];
    }
    else{
        return YES;
    }
}

+ (BOOL) buildPathForFile:(NSString *)filePath
{
	return [PathManager buildPath:[filePath stringByDeletingLastPathComponent]];
}

+ (BOOL) deleteBuildPath:(NSString *)path
{
	return [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}


- (BOOL) buildPath:(NSString *)path
{
	return [PathManager buildPath:path];
}

- (BOOL) buildPathForFile:(NSString *)filePath
{
	return [PathManager buildPathForFile:filePath];
}

- (BOOL) deleteBuildPath:(NSString *)path
{
	return [PathManager deleteBuildPath:path];
}
#pragma mark - root
- (NSString *) applicationDocumentsRootPath
{
	if (applicationDocumentsRootPath == nil) {
		NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
		applicationDocumentsRootPath = ([paths count] > 0 ? [paths objectAtIndex:0] : nil);
	}
	return applicationDocumentsRootPath;
}
-(NSString *)applicationTempPath{
    if (applicationTempPath == nil) {
		applicationTempPath=NSTemporaryDirectory();
	}
	return applicationTempPath;
}
-(NSString *)applicationCachePath{
    if (applicationCachePath==nil) {
    	NSArray * paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
		applicationCachePath = ([paths count] > 0 ? [paths objectAtIndex:0] : nil);
	}
	return applicationCachePath;
}

#pragma mark - target
- (NSString *) docPath
{
	if (docPath == nil) {
		docPath = [[self.applicationDocumentsRootPath stringByAppendingPathComponent:@"BuLuoGame"] copy];
	}
	return docPath;
}
-(NSString *)cachePath{
    if (cachePath==nil) {
        cachePath=[[self.applicationCachePath stringByAppendingPathComponent:@"BuLuoGame"]copy];
    }
    return cachePath;
}
-(NSString *)tempPath{
    if (tempPath == nil) {
		tempPath = [[self.applicationTempPath stringByAppendingPathComponent:@"BuLuoGame"] copy];
	}
	return tempPath;
}

- (NSString *) defaultDatabasePath
{
	if (defaultDatabasePath == nil) {
		defaultDatabasePath = [[self.docPath stringByAppendingPathComponent:SQL_DataBase] copy];
	}
	return defaultDatabasePath;
}

#pragma mark -  Document/BuLuoGame/Basicinfo
- (NSString *) attachmentDocumentPathByName:(NSString *)attachment
{
	NSString * name = nil;
	name = attachment;
	return [[self.docPath  stringByAppendingPathComponent:@"Basicinfo"] stringByAppendingPathComponent:name];
}

#pragma mark - Document/BuLuoGame/BasicImage
- (NSString *) attachmentImagePathByName:(NSString *)attachment{
    NSString * name = nil;
	name = attachment;
	return [[self.docPath  stringByAppendingPathComponent:@"BasicImage"] stringByAppendingPathComponent:name];
}

#pragma mark - library/BuLuoGame/Basicinfo
-(NSString *)attachmentCachePathByName:(NSString *)attachment{
    NSString * name = nil;
	name = attachment;
	return [[self.cachePath  stringByAppendingPathComponent:@"Basicinfo" ]stringByAppendingPathComponent:name];
}

#pragma mark - temp/BuLuoGame
- (NSString *) attachmentTempPathByName:(NSString *)attachment
{
	NSString * name = nil;
	name = attachment;
	return [[self.tempPath  stringByAppendingPathComponent:@"TempImage"] stringByAppendingPathComponent:name];
}


@end
